home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1986 July / Ahoy_Magazine_86-07_1986_Double_L.d64 / sort 64 (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  707b  |  43 lines

  1. 1 print"[147]":poke53280,5:poke53281,0:poke646,7
  2. 2 rem  > insertion sort 64 <
  3. 3 rem    rupert report #31
  4. 4 rem  =-=- basic 2.0 -=-=
  5. 10 m$="this is a test message"
  6. 15 n=len(m$)
  7. 20 dim a$(n) : a$(0)=""
  8. 30 rem - input the array
  9. 40 gosub 220
  10. 50 rem - sort the array
  11. 60 gosub 110
  12. 70 rem - print the sorted array
  13. 80 gosub 300
  14. 90 end
  15. 100 :
  16. 110 rem == insertion sort ==
  17. 120 :
  18. 130 for i=2 to n
  19. 140    v$=a$(i) : j=i
  20. 150    if a$(j-1)<=v$ then 180
  21. 160      a$(j)=a$(j-1) : j=j-1
  22. 170    goto 150
  23. 180 a$(j)=v$
  24. 190 next i
  25. 200 return
  26. 210 :
  27. 220 rem == input array ==
  28. 230 :
  29. 240 for k=1 to n
  30. 250 a$(k)=mid$(m$,k,1)
  31. 260 print a$(k);
  32. 270 next k
  33. 280 return
  34. 290 :
  35. 300 rem == print array ==
  36. 310 :
  37. 320 print:print"sorted:"
  38. 330 for k=1 to n
  39. 340 print a$(k);
  40. 350 next k
  41. 355 print:print"list this program for details"
  42. 360 return
  43.